package com.city.eduservice.controller;


import com.city.commonutils.Result;
import com.city.eduservice.entity.subject.OneSubject;
import com.city.eduservice.service.EduSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author city
 * @since 2020-06-18
 */
@RestController
@RequestMapping("/eduservice/subject")
@CrossOrigin
public class EduSubjectController {
    @Autowired
    private EduSubjectService eduSubjectService;

    //读取上传的文件进行写入数据库
    @PostMapping("addSubject")
    //PathVariable获取路径值，RequestParam获取请求携带参数值，RequestBody获取请求携带的json数据
    public Result addSubject(@RequestParam MultipartFile file){
        eduSubjectService.saveSubject(file,eduSubjectService);
        return Result.ok();
    }

    @GetMapping("getAllSubject")
    public Result getAllSubject(){
        List<OneSubject> allOneTwoSubject= eduSubjectService.getAllOneTwoSubject();
        return Result.ok().data("list",allOneTwoSubject);
    }
}

